

function formatter(time = new Date()) {
    let year = time.getFullYear();
    let month = time.getMonth() + 1;
    let day = time.getDate();
    let hour = time.getHours();
    let minute = time.getMinutes();
    let second = time.getSeconds();
    // console.log(year + "年" + month + "月" + day + "日" + hour + "时" + minute + "分" + second + "秒");
    return year + "年" + month + "月" + day + "日" + hour + "时" + minute + "分" + second + "秒";
}

// let now = new Date();
// formatter(now);


let time = document.querySelector('#time');
// 每隔一秒执行一次
// function timer() {
//     let str = formatter(new Date());
//     time.innerHTML = str;
//     setTimeout(timer, 1000);
// }
// timer();

// 每隔一秒执行一次
let timer = setInterval(function () {
    let str = formatter(new Date());
    time.innerHTML = str;
}, 1000);

function cancel() {
    clearInterval(timer);
}
// setTimeout(function () {
//     console.log("1秒后执行", new Date());
// }, 1000);
// console.log(new Date());
// for (let i = 0; i < 10000000; i++) {
//     let n = new Date();
//     formatter(n);
// }